#include <stdio.h>
#include <stdlib.h>

void CountSort(int* nums, int numsSize)
{
	int max = nums[0];
	int min = nums[0];

	for (int i = 0; i < numsSize; i++)
	{
		if (nums[i] > max)
			max = nums[i];
		if (nums[i] < min)
			min = nums[i];
	}

	int range = max - min + 1;
	int* count = (int*)malloc(sizeof(int) * range);
	memset(count, 0, range * sizeof(int));

	for (int i = 0; i < numsSize; i++)
		count[nums[i] - min]++;

	int cur = 0;
	for (int i = 0; i < range; i++)
	{
		while (count[i]--)
			nums[cur++] = i + min;
	}
}

int main()
{
	int nums[] = { -1,101,105,102,105,1072,6,2,-9,62,6,25,752,7,25,37,26,23,5612,6,37,82,8,828, };
	int len = sizeof(nums) / sizeof(int);
	CountSort(nums, len);
	for (int i = 0; i < len; i++)
		printf("%d ", nums[i]);
	return 0;
}